/*
* Copyright (c) 2016 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
*/
package com.hyyt.shopjsp.util.common;

import java.beans.PropertyEditorSupport;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @author: ankang
 * @Date 2016/7/14 0014 下午 4:53
 */
public class CustomPropertyEditor extends PropertyEditorSupport {

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        SimpleDateFormat format = new SimpleDateFormat(EnumUtils.DataFormat.Y_M_D_H_m_s.getValue());
        Timestamp date = null;
        try {
            date = (Timestamp) format.parse(text);
        } catch (ParseException e) {
            format = new SimpleDateFormat(EnumUtils.DataFormat.Y_M_D.getValue());
            try {
                date = (Timestamp) format.parse(text);
            } catch (ParseException e1) {
                e1.printStackTrace();
            }
        }
        setValue(date);
    }

    @Override
    public String getAsText() {
        return getValue().toString();
    }
}
